"""读配置文件数据"""
import configparser
import pathlib
import csv
import pytest

# 配置文件的路径
file = pathlib.Path(__file__).resolve().parent / 'config.ini'


# **kwargs表示接受不定数量的关键字参数,必须放在参数列表的最后一个位置，并且不能同时出现在函数定义中的其他参数之前。
def read_conf(envs=None, option=None):
    conf = configparser.ConfigParser()
    conf.read(str(file))  # 将路径转换为字符串
    values = conf.get(envs, option)
    return values


def load_test_cases(csv_file):
    test_cases = []
    ids = []  # 用于存储从case_name列获取的ids
    with open(csv_file, mode='r', encoding='utf-8-sig') as f:
        csv_reader = csv.DictReader(f)
        for row in csv_reader:
            # 从row中弹出case_name字段，并将其添加到ids列表中
            case_name = row.pop('case_name')
            ids.append(case_name)
            # 将skip字段从字符串转换为布尔值
            skip_test = row.pop('skip').upper() == 'TRUE'
            # 如果需要跳过，则添加pytest.mark.skipif标记
            mark = pytest.mark.skipif(skip_test, reason="Skipped based on CSV skip field")
            # 使用pytest.param来包装测试数据，并添加标记
            test_cases.append(pytest.param(row, marks=mark))
    # 返回一个元组，包含测试案例和它们的ids
    return test_cases, ids


# 环境
envs_test = "test"
envs2 = "server"

# 读取环境变量
email = read_conf(envs_test, 'email')
email_sec = read_conf(envs_test, 'email_sec')
email_admin = read_conf(envs_test, 'email_admin')
email_team = read_conf(envs_test, 'email_team')
password = read_conf(envs_test, 'password')
password_admin = read_conf(envs_test, 'password_admin')
x_cs_nonce = read_conf(envs_test, 'x_cs_nonce')
basic_path = read_conf(envs_test, 'basic_path')
version = read_conf(envs_test, 'version')
ip = read_conf(envs_test, 'ip')
port = read_conf(envs_test, 'port')
eng_port = int(read_conf(envs_test, 'port')) + 1
cs_url = "http://{}:{}".format(ip, port)
base_url = cs_url + basic_path + version
lang = read_conf(envs_test, 'lang')
test_project = read_conf(envs_test, 'test_project')
test_project_url = read_conf(envs_test, 'test_project_url')

if __name__ == '__main__':
    print(read_conf(envs=envs_test, option='email'))
